import org.apache.spark.sql.{DataFrame, SparkSession}


val spark = SparkSession.builder.appName("SparkSQL-DataQuery").master("local[*]").getOrCreate()
val studentsDF = spark.read.format("jdbc").option("url", "jdbc:mysql://localhost:3306/sparksql_practice").option("dbtable", "students").option("user", "root").option("password", "root").option("driver", "com.mysql.jdbc.Driver").option("useSSL", "false").load()
val olderThan20 = studentsDF.filter($"age" > 20)
olderThan20.show()
val sortedStudents = studentsDF.orderBy($"major".asc, $"enrollment_date".asc)
sortedStudents.show()
val majorCounts = studentsDF.groupBy("major").count()
majorCounts.show()
